#!/bin/bash
echo -e "\033[36m=====================    开始更新后端    ====================== \033[0m"
jar_name=$(ls *.jar)

echo "===判断当前服务是否启动，若启动，则关闭服务再更新==="

if [ $(ps -aux | grep $jar_name | grep -v grep | wc -l) -ne 0 ];then
        echo "服务已启动，现在关闭服务"
        kill -9 `ps -aux |grep $jar_name | grep -v grep | awk '{print $2}'`
fi
echo "启动服务,一分钟后检查服务"
nohup java -jar "$jar_name" > "$jar_name".log &

sleep 60

echo "检查服务进程"

if [ $(ps -aux | grep $jar_name | grep -v grep | wc -l) -ne 0 ];then
    echo "服务已启动,日志如下"
else
    echo "服务未启动，检查日志"
fi
rm -rf deploy-bin.tar.gz